﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataAccess
{
    public class HocKy
    {
        public int MaHK { get; set; }
        public string TenHK { get; set; }

        public HocKy() { }
        public HocKy(int ma, string ten)
        {
            MaHK = ma;
            TenHK = ten;
        }
        public static HocKy GetData(SqlDataReader read)
        {
            HocKy l = new HocKy();
            l.MaHK = CType.ToInt32(read[0]);
            l.TenHK = CType.Tostring(read[1]);
            return l;
        }
        public static List<HocKy> list;
        public static List<HocKy> All()
        {
            list = new List<HocKy>();
            using (SqlConnection conn = MyConnection.MyConn())
            {
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "select * from HocKy";
                conn.Open();
                SqlDataReader read = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                while (read.Read())
                {
                    HocKy l = GetData(read);
                    list.Add(l);
                }
                return list;
            }
        }
    }
}
